import registerView from '../views/register.art'
import addressModels from '../models/address'
import addressListView from '../views/adress.art'


class register{
    constructor(){
        this.render()
        
    }
  async render(){
        let html=registerView({})
        $('#register-root').html(html)
        let result=await addressModels.get();
      //  console.log(result.content.rows)
      let list=result.content.rows;
      
    
      let   addressListHtml= addressListView({
          list
      })
       this.tap() 
      $('#adress-list').html(addressListHtml)  
      $('.dd-list').on('tap',function(ev){ 
          $('#adress-num a em').html($(this).attr('data-code'))
         $('#adress-list').css('display',"none");
         ev.stopPropagation();
      })
    
      this.doregister()
     
    }

    tap(){
        $('#adress-num a').on('tap',function(ev){
        $('#adress-list').css('display',"block");
        ev.stopPropagation();
        console.log(555)
        })
    }

    doregister(){
        if(window.localStorage.userArr){//判断是否存在
          var array = JSON.parse(window.localStorage.userArr);
        }else{
        var	array = [];//创建一个新数组
        
        }
        var pass=document.querySelector('#pass')
        var change=document.querySelector('#change')
      
pass.oninput=function(){  
    if(/^\d+$/.test(pass.value)){
         console.log(123)
        change.innerHTML="弱"
    }else if(/^(?!\d+$)(?![a-zA-Z]+$)[a-zA-Z\d]+$/.test(pass.value)){
        change.innerHTML="中"
      
    }else if(/^(?!\d+$)(?![a-zA-Z]+$)(?![@#$%^&]+$)[\da-zA-Z@#$%^&]+$/.test(pass.value))
    change.innerHTML="强"
}
     $('.submit_btn').on('tap',function(){
        var phone=$('.register').val()
        var password=$('.pass').val() 
 console.log(phone)
        if(!(/^1[3456789]\d{9}$/.test(phone))){ 
        alert("请输入正确手机号");
        return;
     }
//console.log(password)

     for(var i =0;i<array.length;i++){
        //判断是否有相同账号
        if(phone==array[i].phone){
            alert("该账号已存在");
            return;
        }
    }
    var obj = {phone:phone,password:password,score:0}
    array.push(obj);
    window.localStorage.userArr=JSON.stringify(array);
    alert("用户创建成功");
    location.href="../../login.html"
     })   
    }
}
new register()